package com.common.base;

import java.util.HashMap;
import com.common.constant.Codes;

/**
 * 返回数据
 * 
 */
public class Return extends HashMap<String, Object> {

	public static Return error() {
		return error(Codes.ERROR.getCode(), Codes.ERROR.getMessage());
	}
	
	public static Return error(String msg) {
		return error(Codes.ERROR.getCode(), msg);
	}
	
	public static Return error(int code, String msg) {
		Return r = new Return();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	private static Return success(int code,String msg){
		Return r = new Return();
		r.put("code",code);
		r.put("msg",msg);
		return r;
	}

	public static Return success() {
		return success(Codes.SUCCESS.getCode(),Codes.SUCCESS.getMessage());
	}

	public static Return success(String msg) {
		return success(Codes.SUCCESS.getCode(),msg);
	}

	public static Return success(Object obj){
		return success().put(obj);
	}

	public static Return success(String msg,Object obj){
		return success(msg).put(obj);
	}

	public Return put(Object value) {
		super.put("result", value);
		return this;
	}
}
